import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    isShowAside: true, // 是否显示侧边栏
    isLoading: false, // 是否正在登录状态
    user: { // 用户数据
      username: '',
      appkey: '',
      email: '',
      role: ''
    },
    menus: [], // 路由信息
  },
  mutations: {
    // 修改侧边栏的显示
    changeShowAside(state) {
      state.isShowAside = !state.isShowAside;
    },
    // 修改用户数据
    changeUser(state, {
      username,
      email,
      role,
      appkey
    }) {
      state.user.username = username;
      state.user.email = email;
      state.user.role = role;
      state.user.appkey = appkey;
    },
    changeLoginState(state, params) {
      state.isLoading = params;
    },
    changeMenu(state, params) {
      state.menus = params;
    }
  },
  actions: {
    // 异步修改侧边栏显示
    asyncChangeShowAside({
      commit
    }) {
      commit('changeShowAside');
    },
    async asyncChangeUser({
      commit
    }, params) {
      commit('changeUser', params)
    },
    asyncChangeMenu({
      commit
    }, params) {
      commit('changeMenu', params)
    }
  },
  modules: {

  },
});